package model.semantics;

import java.util.LinkedList;
import java.util.List;

import model.State;

/**
 * Represents an abstract Node on the expression tree, which returns a value of
 * type T.
 * @author Sterling Dorminey
 *
 */
public class Node<T> {
	List<Node<T>> myChildren;
	
	public Node(){
		myChildren = new LinkedList<Node<T>>();
	}
	
	public Node(List<Node<T>> children) {
		myChildren = children;
	}

	/**
	 * Evaluates the node given the state parametrized by T.
	 */
	public T evaluate(State<T> state) {
		T output = null;
		for(Node<T> child : myChildren) {
			output = child.evaluate(state);
		}
		return output;
	}
	
	public List<T> evaluateList(State<T> state){
		List<T> rtn = new LinkedList<T>();
		for(Node<T> child : myChildren){
			rtn.add(child.evaluate(state));
		}
		return rtn;
	}
	
	@Override
	public String toString() {
//		return String.format("(agg %s)", myChildren.toString());
		return myChildren.toString();
	}

}
